"""
运行测试脚本

设置正确的PYTHONPATH并运行所有测试用例
"""

import sys
import os
import unittest

# 获取项目根目录
project_root = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(project_root)

# 添加项目根目录到Python路径
if parent_dir not in sys.path:
    sys.path.insert(0, parent_dir)

# 运行所有测试
if __name__ == "__main__":
    print(f"设置PYTHONPATH: {parent_dir}")
    test_loader = unittest.TestLoader()
    test_suite = test_loader.discover(os.path.join(project_root, "tests"))
    
    # 运行测试
    test_runner = unittest.TextTestRunner(verbosity=2)
    result = test_runner.run(test_suite)
    
    # 根据测试结果设置退出码
    sys.exit(not result.wasSuccessful())